<%@page import="java.util.*"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="org.json.simple.JSONObject"%>
<%@ page import="org.json.simple.JSONArray"%>
<%@ page import="java.net.URLEncoder"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String mcode=request.getParameter("mcode");
	//String mcode="M1";

	String url="jdbc:oracle:thin:@192.168.0.18:1521:orcl";
	String user="book";
	String password="book";
	String sql=null;
	
	Connection conn=null;
	ResultSet rs=null;
	PreparedStatement stmt=null;
	
	try{
		Class.forName("oracle.jdbc.driver.OracleDriver");
		//out.println("드라이버 로딩 성공");
		conn=DriverManager.getConnection(url, user, password);
		//out.println("접속 성공");
		
		sql="SELECT * FROM BOARD WHERE MCODE=? ORDER BY BDATE DESC";
		
		stmt=conn.prepareStatement(sql);
		
		stmt.setString(1, mcode);
		rs = stmt.executeQuery();
		
		JSONObject jsonMain=new JSONObject();
		JSONArray arr=new JSONArray();
		JSONArray arr1=new JSONArray();
		
	
		while(rs.next())
		{
			
			JSONObject obj=new JSONObject();
			String bcontent=rs.getString("bcontent");
			String bcode=rs.getString("bcode");
			String bbgimage=rs.getString("bbgimage");
			//String mname=rs.getString("mname");
			String bfont=rs.getString("bfont");
			String bfontbg=rs.getString("bfontbg");
			String bposition=rs.getString("bposition");
			String bcoordinate=rs.getString("bcoordinate");
			String bbookurl=rs.getString("bbookurl");
			String bfontsize=rs.getString("bfontsize");
			
			obj.put("bcontent", bcontent);
			obj.put("bcode", bcode);
			obj.put("bbgimage", bbgimage);
			obj.put("bfont", bfont);
			obj.put("bfontbg", bfontbg);
			obj.put("bposition", bposition);
			obj.put("bcoordinate", bcoordinate);
			obj.put("bbookurl", bbookurl);
			obj.put("bfontsize", bfontsize);
			
			arr.add(obj);
			//obj1.put("c", obj);
			//arr1.add(obj1);
		
		}
		
		jsonMain.put("dataSend", arr);
		out.println(jsonMain);
		
	}catch(Exception e){
		out.println("접속 실패");
		e.printStackTrace();
	}finally{
		if(stmt!=null) stmt.close();
		if(conn!=null) conn.close();
	}
	
%>